<!DOCTYPE html>
<html lang="zh-cmn-Hans" prefix="og: http://ogp.me/ns#" class="han-init">
<head>
  <meta charset="utf-8">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <link rel="icon" href="http://upeng.github.io/favicon.ico">
  <title>upeng</title>
  <link rel="stylesheet" href="/css/style.css">
  <link rel="stylesheet" href="/lib/fancybox/jquery.fancybox-1.3.4.css">
  <!--在这里倒入jquery 方便处理部分页面的jquery-->
  <script src="https://cdn.staticfile.org/jquery/1.7/jquery.min.js" type="text/javascript" ></script>
</head>

<body>
	<header class="site-header navfixed-false">
  <div class="container">
      <h1><a href="/" title="upeng"><span class="octicon octicon-mark-github"></span> upeng</a></h1>
      <nav class="site-header-nav" role="navigation">
        
              
              <a href="/"  class=" site-header-nav-item hvr-underline-from-center" title="Home">Home</a>
        
              
              <a href="/categories/"  class=" site-header-nav-item hvr-underline-from-center" title="Categories">Categories</a>
        
              
              <a href="/bookmark/"  class=" site-header-nav-item hvr-underline-from-center" title="Bookmark">Bookmark</a>
        
              
              <a href="http://shareup.sinaapp.com"  class=" site-header-nav-item hvr-underline-from-center" title="Share">Share</a>
        
              
              <a href="/about/"  class=" site-header-nav-item hvr-underline-from-center" title="About">About</a>
        
      </nav>
  </div>
</header>

	
<section class="collection-head geopattern" data-pattern-id="vagrant-快速搭建linux开发环境" >
    <div class="container">
        <div class="collection-title">
            <h1 class="collection-header">
                vagrant-快速搭建linux开发环境
            </h1>
            
                <div class="collection-info">
                    <span class="meta-info">
                        <span class="octicon octicon-calendar"></span>
                        <time datetime="2016-07-13T15:32:54.000Z" itemprop="datePublished">2016-07-13</time>
                    </span>
                    
                        <span class="meta-info">
                            <span class="octicon octicon-file-directory"></span>
                            <a href='/categories/乱炖/' title=''>乱炖</a>
                        </span>
                    
                </div>
            
        </div>
    </div>
</section>
	<section class="container">
    <div class="columns">
        <!-- -->
        <div class="column three-fourths">
            <article class="article-content markdown-body">
                <p>平时开发测试使用公司提供的弹性开发机（Centos），自己想折腾一些东西又不方面在上面部署,鉴于</p>
<ul>
<li>学习linux考虑（比如经常装扩展插件啥的），装WAMP有些low而且不适合扩展。</li>
<li>在windows上装linux虚拟机（VMare等）又太占内存（o(╯□╰)o我的笔记本只有4G内存。。。）</li>
</ul>
<p>有没有那种快捷的搭建linux开发环境的东东呢？答案是肯定的。偶然间发现了vagrant，它就像一个容器一样（Docker？），部署LAMP十分快捷；<br><a id="more"></a></p>
<h2 id="我所理解的vagrant-box"><a href="#我所理解的vagrant-box" class="headerlink" title="我所理解的vagrant box"></a>我所理解的vagrant box</h2><p>我理解的，vagrant box就是一个简易linux操作系统内核，到vagrant官网可以看到很多【<a href="http://www.vagrantbox.es/】，" target="_blank" rel="external">http://www.vagrantbox.es/】，</a> 选择一个box下载下来，然后通过vagrant add box就可以直接初始化一个linux系统了；如果你想创建多个linux系统，那就多add 几个，所以vagrant也可以练习分布式！但是，这个网站的速度也慢的可以，推荐一个国内镜像，还是挺快的，每秒20M左右 【<a href="http://mirrors.hypo.cn/ubuntu-vagrant/】" target="_blank" rel="external">http://mirrors.hypo.cn/ubuntu-vagrant/】</a></p>
<h2 id="预备软件"><a href="#预备软件" class="headerlink" title="预备软件"></a>预备软件</h2><p>virtualBox : 运行linux的环境 【<a href="https://www.vagrantup.com/】" target="_blank" rel="external">https://www.vagrantup.com/】</a><br>vagrant：提供一些vagrant命令 【<a href="https://www.virtualbox.org/】" target="_blank" rel="external">https://www.virtualbox.org/】</a><br>百度云盘备份：【<a href="http://pan.baidu.com/s/1o8aoofo】" target="_blank" rel="external">http://pan.baidu.com/s/1o8aoofo】</a></p>
<h2 id="vagrant-box下载"><a href="#vagrant-box下载" class="headerlink" title="vagrant box下载"></a>vagrant box下载</h2><p>记得第一次是“在线”下载vagrant box，执行vagrant init；vagrant up之后，当检测到无box时会自动下载；速度慢的惊人（虽然我开了vpn），而且在线安装的box直接就在我们vagrant up命令中执行了，没有见到box后缀的文件，当你重装系统后或者你安装的vagrant损坏后，难道又要重新在线安装box？ +_+ 所以建议下载box文件，然后使用vagrant add box命令</p>
<h2 id="vagrant-常用命令-快速搭建LAMP流程"><a href="#vagrant-常用命令-快速搭建LAMP流程" class="headerlink" title="vagrant 常用命令(快速搭建LAMP流程)"></a>vagrant 常用命令(快速搭建LAMP流程)</h2><h3 id="添加box"><a href="#添加box" class="headerlink" title="添加box"></a>添加box</h3><p>vargant box add  trusty  trusty-server-cloudimg-amd64-vagrant-disk1.box<br>// vagrant box add  box默认名称是base,此处我们定义为trusty  .box文件就是我们下载的box</p>
<h3 id="初始化"><a href="#初始化" class="headerlink" title="初始化"></a>初始化</h3><p>vagrant init<br>因为我们重新命名了我们的box为trusty，所以你再任何地方只要执行vagrant init，生成的Vagrant文件中config.vm.box=’trusty’；<br>如果执行vagrant up会失败，因为vagrant init默认以base为名初始化；正确的初始化姿势是<br>vagrant init trusty</p>
<h3 id="启动虚拟机"><a href="#启动虚拟机" class="headerlink" title="启动虚拟机"></a>启动虚拟机</h3><p>vargant up<br>vagrant up之前需要将Vagrant文件的第25行注释去掉，这样才能在windows中访问我们在linux中创建的程序；在trusty版本的Ubuntu中，有个目录 <code>/vagrant</code>与本地windows中Vagrant同级，因此可以本地编辑，linux中运行，就像磁盘映射。</p>
<h3 id="登录虚拟机"><a href="#登录虚拟机" class="headerlink" title="登录虚拟机"></a>登录虚拟机</h3><p>vagrant ssh<br>使用vagrant ssh进入Ubuntu系统；进入后需要更新升级Ubuntu的一些包和工具，同事需要安装我们的LAMP。<br>升级包命令： <code>sudo apt-get update</code><br>安装php apache: <code>sudo apt-get install apache2 php5 libapache2-mod-php5</code><br>安装mysql: <code>sudo apt-get install mysql-server mysql-client php5-mysql</code></p>
<h3 id="配置apache2"><a href="#配置apache2" class="headerlink" title="配置apache2"></a>配置apache2</h3><p>安装完成后访问：<code>http://localhost:8080</code> , 默认指向 <code>/var/www/html</code> ,修改配置文件如下：<br>配置文件路径  <code>/etc/apache2/sites-available/000-default.conf</code></p>
<pre><code>DocumentRoot /vagrant
&lt;Directory /vagrant&gt;
                Options -Indexes +followSymLinks +MultiViews
                AllowOverride all
                Require all granted
&lt;/Directory&gt;
</code></pre><p>修改完成后重启apache <code>service apache2 restart</code></p>
<p>参考：<br><a href="http://rrylee.github.io/2015/11/26/quick-start-linux-php/" target="_blank" rel="external">http://rrylee.github.io/2015/11/26/quick-start-linux-php/</a><br><a href="http://rmingwang.com/vagrant-commands-and-config.html" target="_blank" rel="external">http://rmingwang.com/vagrant-commands-and-config.html</a></p>

            </article>
            
                <div class="share">
                    <!--开启分享-->
<div class="share-component" data-disabled="google,twitter,facebook" data-description="平时开发测试使用公司提供的弹性开发机（Centos），..."></div>

<script src="/js/share.min.js"></script>

                </div>    
            
            
                
<div class="comments">
	<div class="ds-thread" data-thread-key="vagrant" data-title="vagrant-快速搭建linux开发环境" data-url="http://upeng.github.io/2016/07/13/vagrant/"></div>
	<script type="text/javascript">
	var duoshuoQuery = {short_name:"upeng"};
		(function() {
			var ds = document.createElement('script');
			ds.type = 'text/javascript';ds.async = true;
			ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
			ds.charset = 'UTF-8';
			(document.getElementsByTagName('head')[0]
			 || document.getElementsByTagName('body')[0]).appendChild(ds);
		})();
	</script>
</div>

            
        </div>
        <div class="column one-fourth">
            
                
                


<h3>Post Directory</h3>

<div id="post-directory-module">
	<section class="post-directory">
		<p><strong class="toc-title">文章目录</strong></p>
		<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#我所理解的vagrant-box"><span class="toc-text">我所理解的vagrant box</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#预备软件"><span class="toc-text">预备软件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#vagrant-box下载"><span class="toc-text">vagrant box下载</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#vagrant-常用命令-快速搭建LAMP流程"><span class="toc-text">vagrant 常用命令(快速搭建LAMP流程)</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#添加box"><span class="toc-text">添加box</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#初始化"><span class="toc-text">初始化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#启动虚拟机"><span class="toc-text">启动虚拟机</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#登录虚拟机"><span class="toc-text">登录虚拟机</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#配置apache2"><span class="toc-text">配置apache2</span></a></li></ol></li></ol>
	</section>
</div>
            
        </div>
    </div>
</section>

<footer class="container">
    <div class="site-footer" role="contentinfo">
        <div class="copyright left mobile-block">
                © 2016
                <span title="yupeng">yupeng</span>
                <a href="javascript:window.scrollTo(0,0)" class="right mobile-visible">TOP</a>
        </div>

        <ul class="site-footer-links right mobile-hidden">
            <li>
                <a href="javascript:window.scrollTo(0,0)" >TOP</a>
            </li>
        </ul>

        <a href="https://github.com/upeng" target="_blank" aria-label="view source code">
            <span class="mega-octicon octicon-mark-github" title="GitHub"></span>
        </a>

        <ul class="site-footer-links mobile-hidden">
            
                  
                  <li>
                    <a href="/"  title="Home">Home</a>
                  </li>
            
                  
                  <li>
                    <a href="/categories/"  title="Categories">Categories</a>
                  </li>
            
                  
                  <li>
                    <a href="/bookmark/"  title="Bookmark">Bookmark</a>
                  </li>
            
                  
                  <li>
                    <a href="http://shareup.sinaapp.com"  title="Share">Share</a>
                  </li>
            
                  
                  <li>
                    <a href="/about/"  title="About">About</a>
                  </li>
            
            <li>
                <a href="/atom.xml">
                    <span class="octicon octicon-rss" style="color:orange;"></span>
                </a>
            </li>
        </ul>
    </div>
</footer>


		<script src="/js/geopattern.js"></script>

		
			<script src="/js/toc.js"></script>
		

		<script src="/js/highlight.pack.js"></script>
		<script src="/lib/fancybox/jquery.fancybox-1.3.4.pack.js"></script>

		<script src="/js/index.js"></script>

		 <script src="/js/popular_repo.js"></script> 

	</body>
</html>